home *** CD-ROM | disk | FTP | other *** search
- Path: colossus.holonet.net!russell
- From: russell@news.mdli.com (Russell Blackadar)
- Newsgroups: comp.lang.c++
- Subject: Re: Some help with a linker error...
- Date: 18 Jan 1996 03:19:31 GMT
- Organization: HoloNet National Internet Access System: 510-704-1058/modem
- Message-ID: <4dke83$p7l@colossus.holonet.net>
- References: <00001a81+00008ede@msn.com>
- NNTP-Posting-Host: jubal.mdli.com
- X-Newsreader: TIN [version 1.2 PL2]
-
- Tony Bateman (Tony_Bateman@msn.com) wrote:
-
- [deletia]
-
- : the global variables are part of another class ASE, which is defined
- : in another module...
-
- Whoa, that's your problem. You've confused the concept of global
- variables with the concept of class friendship. Totally unrelated
- concepts!
-
- You have:
-
- : extern int numberOfRules;
- : extern fuzzyGaussFunc *pThisFuzzyFunc;
- : extern fuzzyGaussFunc *pFuzzyGfunc;
-
- For a .cpp file with these statements to link correctly, you
- need statements like the following in some other .cpp file:
-
- int numberOfRules = 29; // or whatever
- fuzzyGaussFunc *pThisFuzzyFunc = 0; // or some real function?
- fuzzyGaussFunc *pFuzzyGfunc = 0; // etc...
-
- The initializations are optional, zero if unspecified. They
- *cannot* be inside some class definition, and the variables
- cannot be members of a class. What you did instead was to
- define these variables as members of a class ASE, so the
- linker found no globals to resolve your externs.
-
- By the way, if you do want them to be class members, you'll
- need to rethink your design. Even a friend function must
- have an object (i.e. an instantiation of the class) to use
- them, unless they're static.
-
- : void ACE2::UpdatePt()
- : {
- : ptMinus1 = pt;
- : pt = 0;
- : for (int i=0; i<numberOfRules; i++)
- ^^^^^^^^^^^^^
- Hmm, if this is an ASE member, you need to specify an ASE object,
- e.g.
- ASE some_object; // construct an object
- for (int i=0; i<some_object.numberOfRules; i++) ...
-
- which might not make sense for you. What should the ASE object
- be here, and if none makes sense, why is numberOfRules a member
- of ASE at all? Perhaps it should be a static member, in which
- case you'd need
-
- for (int i=0; i<ASE::numberOfRules; i++) ...
- ^^^^^
- (Maybe that is OK for you?) Similar considerations apply for
- the other two variables in question.
-
- : Any idea why the "_" has been appended to the variables, and what is
- : happening?
-
- Compilers often "mangle" external names, and C++ compilers routinely
- do so (much worse than this, for functions). This won't get in the
- way if you do things right, but if you forget something, sometimes
- the mangling makes it hard to tell exactly what's missing.
-
- Good luck!
- --
- Russell Blackadar, russell@mdli.com
-